package com.ruyuan.twelve.juc._26;

import java.lang.reflect.Proxy;
import java.util.concurrent.ExecutorService;

/**
 * 用于生产proxy组件
 * proxy组件注意不要和jdk中的proxy类混淆
 */
public class ProxyFactory {

    public static <T>T newInstance(Class<T> interfaces, ExecutorService scheduler,Servant servant){
        CustomInvocationHandler customInvocationHandler = new CustomInvocationHandler(servant,scheduler);

        T proxy = (T) Proxy.newProxyInstance(
                interfaces.getClassLoader(),
                new Class[]{interfaces},
                customInvocationHandler
        );
        return proxy;
    }

}
